package com.example.jbmsuppliers.sinopec.activity;

import android.Manifest;
import android.app.Activity;
import android.bluetooth.BluetoothAdapter;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.SharedPreferences;
import android.graphics.Typeface;
import android.net.ConnectivityManager;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.provider.Settings;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.text.Spannable;
import android.text.SpannableStringBuilder;
import android.text.style.StyleSpan;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.example.jbmsuppliers.R;
import com.example.jbmsuppliers.sinopec.adapter.FragmentAdapter;
import com.example.jbmsuppliers.sinopec.doorjurisd.DoorOpenBlue;
import com.example.jbmsuppliers.sinopec.doorjurisd.SensorService;
import com.example.jbmsuppliers.sinopec.net.NetAddRess;
import com.example.jbmsuppliers.sinopec.net.NetWork;
import com.example.jbmsuppliers.sinopec.net.busheven.UtlisNetWork;
import com.example.jbmsuppliers.sinopec.orderaddress.MyAddRessRepair;
import com.example.jbmsuppliers.sinopec.permissions.PermissionsActivity;
import com.example.jbmsuppliers.sinopec.permissions.PermissionsChecker;
import com.example.jbmsuppliers.sinopec.utlis.ExitAppUtlis;
import com.example.jbmsuppliers.sinopec.utlis.SaveOpenKeyManage;
import com.example.jbmsuppliers.sinopec.view.DialogLoading;
import com.example.jbmsuppliers.sinopec.view.DoubleButtonDialog;
import com.example.jbmsuppliers.sinopec.view.MyToast;
import com.example.permission.myjbm.activitys.SearchAty;
import com.example.permission.myjbm.fragments.MyFragment;
import com.example.permission.myjbm.net.ReleaseNet;
import com.example.permission.myjbm.utils.Identifying;
import com.example.permission.myjbm.utils.LoginSharedPreferences;
import com.jbm.jbmsupplier.util.ICertAddressCtrl;
import com.jbm.jbmsupplier.util.IEGuardKey;
import com.jbm.jbmsupplier.util.IEGuardKeyCtrl;
import com.jbm.jbmsupplier.util.IWeatherCtrl;
import com.jbm.jbmsupplier.util.enums.ClickTimesType;

import java.util.ArrayList;
import java.util.List;

import butterknife.InjectView;
import example.qr_codescan.MipcaActivityCapture;


/**
 * Created by 家帮忙 on 2017/1/12.
 */

public class NewHomeActivity extends ActivityUse implements View.OnClickListener {
    public final static int OPDE_DOOR = 0002;
    private final int DUJDE = 0003;
    private final int SOUSUO = 0004;
    private final int SAOMIAO = 0005;
    private final int LUNBO = 0006;
    private final int NONET=0007;
    private final int LOGINEC=0101;
    @InjectView(R.id.tabs)
    TabLayout tabs;
    @InjectView(R.id.viewpager)
    ViewPager viewpager;
    // 所需的全部权限
    static final String[] PERMISSIONS = new String[]{Manifest.permission.INSTALL_SHORTCUT,Manifest.permission.WRITE_EXTERNAL_STORAGE, Manifest.permission.READ_CALENDAR, Manifest.permission.CAMERA, Manifest.permission.ACCESS_COARSE_LOCATION, Manifest.permission.RECORD_AUDIO, Manifest.permission.READ_PHONE_STATE,Manifest.permission.INSTALL_SHORTCUT};//,Manifest.permission.WRITE_SETTINGS
    private PermissionsChecker mPermissionsChecker; // 权限检测器
    private static final int REQUEST_CODE = 0; // 请求码

    //轮播图首页
    private int pageCurrent = 0;
//    private ArrayList arr;
    private final static int SCANNIN_GREQUEST_CODE = 213;
    private ArrayList<IEGuardKey> ArrayListIEKey;
    public NewHomeActivity context;
    private Intent floatintetnt, intentsensor;
    private SharedPreferences sharedPreferences;
    @InjectView(R.id.goback_ps_all)
    Button gobackPsAll;
    private TextView home_sear;
    private ImageView home_fix,home_weaterPhone;
    private final int ADDRESSLISTSHOW = 0x210;
    public  static   int address=7152;
    private   List<Fragment> fragments;
    private MyNetWorkBroadCast network;
    private TextView home_date,home_weater_te,home_zouji,home_dushu,_homekongqi,home_xianh;
    private SharedPreferences weather;
    private SharedPreferences mSharedPreferences;
    DialogLoading loader;

    List<String> titles;//标题栏

    Handler handler = new Handler() {
        @Override
        public void handleMessage(Message msg) {
            super.handleMessage(msg);
            switch (msg.what) {
                case OPDE_DOOR: {
                    //清空，来控制开门的数值
                    getSharedPreferences("open_key_judge", Activity.MODE_PRIVATE).edit().clear().commit();
                    IEGuardKeyCtrl result = (IEGuardKeyCtrl) msg.obj;
                    ArrayListIEKey = new ArrayList<>();
                    if (result.back) {
                        try {
                            for (int i = 0; i < result.count; i++) {
                                IEGuardKey keyctrl = result.IndexofList(i);
                                SaveLoginID("login_id", keyctrl.login_id + "");
                                ArrayListIEKey.add(keyctrl);
                                mloginsherd.saveOverDate(keyctrl.close_date);

                            }
                            //保存用户开门key
                            new SaveOpenKeyManage(NewHomeActivity.this).setsaveOpenkey(ArrayListIEKey);
//                            handler.sendMessage(handler.obtainMessage(DUJDE));
                            handler.sendEmptyMessageAtTime(DUJDE,500);
                        } catch (Exception e) {
                        }
                    } else if (result.equals("time out")) {

                    } else if (result.equals("Exception")) {

                    }
                    break;
                }
                case LOGINEC:{
                    String resul = (String) msg.obj;
                    if (resul != null) {
                        if (resul.equals("Login OK")) {
                            getDoorKey();
                        } else if (resul.equals("FAILED")) {
                            return;
                        } else {
                            return;
                        }
                    }
                    break;
                }
                case DUJDE: {
                    IsKey();
                    break;
                }
                case SAOMIAO: {
                    //跳转到扫码页
                    Intent intentsao = new Intent(NewHomeActivity.this, MipcaActivityCapture.class);
                    intentsao.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                    startActivityForResult(intentsao, SCANNIN_GREQUEST_CODE);
                    break;
                }
                case SOUSUO: {
                    Intent intent = new Intent(NewHomeActivity.this, SearchAty.class);
                    intent.putExtra("address",address);
                    startActivity(intent);
                    break;
                }
                case LUNBO: {
//                    pageCurrent++;
//                    if (pageCurrent >= 3) {
//                        pageCurrent = 0;
//                    }
//                    vp.setCurrentItem(pageCurrent);
//                    handler.sendEmptyMessageDelayed(LUNBO, 2000);
                    break;


                }
                case ReleaseNet.WEATHERERROR1:
                    IWeatherCtrl info = (IWeatherCtrl) msg.obj;
                    if (info.back) {
                    editwether.putString("city", info.weather.city)
                            .putString("cond", info.weather.cond)
                            .putString("tmp", info.weather.tmpmin + "C°" + "-" + info.weather.tmpmax + "C°")
                            .putString("winddir", info.weather.winddir)
                            .putString("windsc", info.weather.windsc)
                            .putString("aqi", info.weather.aqi)
                            .putString("date", info.trafficRstr.date)
                            .putString("week", info.trafficRstr.week)
                            .putString("number", info.trafficRstr.number)
                            .putString("qlty", info.weather.qlty)
                            .putString("temp",info.weather.tmp)
                            .commit();
//                        1.城市,2.天气,3.温度,4.风力,5.风向,6.空气质量
//                        7.年月日,8.星期几,9.限行,10.空气优良,11.温度最大值
                    setWeatherDate(info.weather.city, info.weather.cond, info.weather.tmpmin + "C°" + "-" + info.weather.tmpmax + "C°", info.weather.winddir, info.weather.windsc, info.weather.aqi, info.trafficRstr.date, info.trafficRstr.week, info.trafficRstr.number, info.weather.qlty,info.weather.tmp);
                    getAddress();

                }else{
                        handler.sendMessage(handler.obtainMessage(NONET));
                        ((MyFragment) fragments.get(0)).setType(index,address);
                    }
                    break;

                case NONET:{
                    IsKey();
                    String city = weather.getString("city", "");
                    String cond = weather.getString("cond", "");
                    String tmp = weather.getString("tmp", "");
                    String winddir = weather.getString("winddir", "");
                    String windsc = weather.getString("windsc", "");
                    String aqi = weather.getString("aqi", "");
                    String date = weather.getString("date", "");
                    String week = weather.getString("week", "");
                    String number = weather.getString("number", "");
                    String qlty = weather.getString("qlty", "");
                    String temp=weather.getString("temp","");
                    setWeatherDate(city, cond, tmp, winddir, windsc, aqi, date, week, number, qlty,temp);
                    ((MyFragment) fragments.get(0)).setType(index,address);
                    break;
                }
                case ADDRESSLISTSHOW: {
                    ICertAddressCtrl ctrl = (ICertAddressCtrl) msg.obj;
//                    if (ctrl.back) {
//                        if (dialogLoading != null) {
//                            dialogLoading.setTextstr("加载成功...");
//                            handler.sendEmptyMessageDelayed(EXIT, 2000);
//                        }
                    if(ctrl.CAlist==null){
                        address=7152;
                        ((MyFragment) fragments.get(0)).setType(index,address);
                        return;
                    }
                    if(ctrl.CAlist[0].gi_id==0){
                        address=7152;
                    }else {
                        address = ctrl.CAlist[0].gi_id;
                   }
                    ((MyFragment) fragments.get(0)).setType(index,address);
                    break;

                }

            }
            loader.dismiss();
        }
    };
    private SharedPreferences.Editor editwether;
    private int modework;
    private BluetoothAdapter _bluetooth;
    private LoginSharedPreferences mloginsherd;
    private ReleaseNet net;


    @Override
    protected int setContentView1() {
        return R.layout.home;
    }

    @Override
    protected void initView() {
         loader=new DialogLoading(this);
        loader.show();
        init();
        initWeater();
        context = this;
        mPermissionsChecker = new PermissionsChecker(this);
        network = new MyNetWorkBroadCast();//监听网络
        registerReceiver(network, new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION));
        mSharedPreferences = getSharedPreferences("sinopecall",
                Activity.MODE_PRIVATE);//保存微信登录和手机号登录的值
        mloginsherd=  new LoginSharedPreferences(this);
        weather = getSharedPreferences("seather", MODE_PRIVATE);//保存车号和天气的改变另加一个登录的id键
        editwether=weather.edit();
        sharedPreferences = getSharedPreferences("dubje", Activity.MODE_PRIVATE);//保存悬浮窗和摇一摇的开关
        getSharedPreferences("open_key_judge", Activity.MODE_PRIVATE).edit().clear().commit();//清空保存蓝牙值
        //轮播图
        //    initView();
        //创建导航栏
        //    initNavigation();
        //内容
//        initContent();
        //调取数据接口

        //   net.getMessageList(1,);
        ceshi();
        bindBroad();
        setTooth();//是否开启蓝牙


    }

    private void setTooth() {
        _bluetooth = BluetoothAdapter.getDefaultAdapter();
        if (_bluetooth == null) {
            return;
        }
        if (_bluetooth.isEnabled() == false) {
            if (!_bluetooth.isEnabled()) {
                Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
                startActivityForResult(enableBtIntent, 1);
            }
        }
    }
    private void init() {
        viewpager = (ViewPager) findViewById(R.id.viewpager);
        tabs = (TabLayout) findViewById(R.id.tabs);
        home_date = (TextView) findViewById(R.id.home_date);
        home_weater_te = (TextView) findViewById(R.id.home_weater_te);
        home_zouji = (TextView) findViewById(R.id.home_zouji);
        home_dushu = (TextView) findViewById(R.id.home_dushu);
        _homekongqi = (TextView) findViewById(R.id._homekongqi);
        home_xianh = (TextView) findViewById(R.id.home_xianh);
        home_sear=(TextView)findViewById(R.id.home_sear);
        home_fix=(ImageView)findViewById(R.id.home_fix);
        //天气图片
        home_weaterPhone=(ImageView)findViewById(R.id.home_weaterPhone);
        LinearLayout weather_lin = (LinearLayout) findViewById(R.id.weather_lin);
        net=new ReleaseNet(handler);
        weather_lin.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if(isNet!=true){
                    net.setLog(ClickTimesType.weather.toValue(),0, Identifying.getFLG(NewHomeActivity.this));
                }

            }
        });
        home_fix.setOnClickListener(this);
        home_sear.setOnClickListener(this);
        ExitAppUtlis.getInstance().addActivity(this);
    }

    //绑定广播 用来检测是否登录或退出
    public void bindBroad(){
        registerReceiver(new BroadcastReceiver() {
            @Override
            public void onReceive(Context context, Intent intent) {
                if(!intent.getBooleanExtra("isLogin",false)){
                    getDoorKey();
                }
                if (intent.getStringExtra("relogin").equals("login")){
                    setLogin();
                }
               viewpager.setCurrentItem(0);
//                ((MyFragment) fragments.get(0)).setType(index,address);
                getAddress();
            }
        },new IntentFilter("isBack"));
    }

    public void getAddress(){
        NetAddRess netAddRess = new NetAddRess(handler);
        netAddRess.AddressMessage(ADDRESSLISTSHOW);
    }

    private void initWeater(){

        net.getWeather();
    }
    //判断栏目是的下标
  private int index;
    private void ceshi() {
        titles = new ArrayList<>();
        titles.add("全部");
        titles.add("热销");
    //    titles.add("服务");
        titles.add("互助");
        titles.add("趣闻");
        titles.add("公共");
        for (int i = 0; i < titles.size(); i++) {
            tabs.addTab(tabs.newTab().setText(titles.get(i)));
        }
          fragments = new ArrayList<>();
        fragments.clear();
        for (int i = 0; i < titles.size(); i++) {
            MyFragment myFragment = new MyFragment();
            fragments.add(myFragment);
        }
        FragmentAdapter mFragmentAdapteradapter = new FragmentAdapter(getSupportFragmentManager(), fragments, titles);
        //给ViewPager设置适配器
        viewpager.setAdapter(mFragmentAdapteradapter);
        //将TabLayout和ViewPager关联起来。
        tabs.setupWithViewPager(viewpager);
        //给TabLayout设置适配器
        tabs.setTabsFromPagerAdapter(mFragmentAdapteradapter);
        viewpager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
            @Override
            public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

            }
            @Override
            public void onPageSelected(int position) {
                        switch(position){
                            case 0:
                                index=0;
                                break;
                            case 1:
                                index=1;
                                break;
//                            case 2:
//                                index=3;
//                                break;
                            case 2:
                                index=4;
                                break;
                            case 3:
                                index=6;
                                break;
                            case 4:
                                index=2;
                                break;
                        }
                ((MyFragment) fragments.get(position)).setType(index,address);
            }

            @Override
            public void onPageScrollStateChanged(int state) {

            }
        });
    }
    //    @OnClick({R.id.sou, R.id.sao})
//    public void onClick(View view) {
//        switch (view.getId()) {
//            case R.id.sou:
//                handler.sendMessage(handler.obtainMessage(SOUSUO));
//                break;
//            case R.id.sao:
//                handler.sendMessage(handler.obtainMessage(SAOMIAO));
//                break;
//        }
//    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        unregisterReceiver(network);
    }




    public void setLogin(){//登陆
    if (mloginsherd.getLoginState() != true) {
        return;
    } else {
    String  name= mSharedPreferences.getString("phname","");
    String  pwd=mSharedPreferences.getString("phpwd","");
    if (name.equals("")){
        return;
    }else{
        NetWork net=new NetWork(handler);
        net.Login(name,pwd,LOGINEC);

    }
}
}
    public void getDoorKey() {//获取用户开门的key
        NetWork network = new NetWork(handler);
        network.getDoorKeyManage();
    }
    //用来做有无网络标志
    private boolean isNet;
    class MyNetWorkBroadCast extends BroadcastReceiver {
        @Override
        public void onReceive(Context context, Intent intent) {
            if (intent.getAction().equals(ConnectivityManager.CONNECTIVITY_ACTION)){
                 modework = UtlisNetWork.getnetwokstate(context);
                if (modework == 0||modework == 1) {
                    if (mloginsherd.getLoginState() == true) {
                        setLogin();//有网络登录
                    }
                     new DoorOpenBlue().getkaimens();
                    isNet=false;
        } else if (modework == -1) {
            handler.sendMessage(handler.obtainMessage(NONET));
          hint("未连接网络,链接网络后才能正常使用...");
                    isNet=true;
            return;
        }
            }
        }

    }


    //轮播图
//    private void initView() {
//        arr = new ArrayList();
//        ImageView img = new ImageView(this);
//        img.setImageResource(R.mipmap.homehelp_home);
//        img.setScaleType(ImageView.ScaleType.FIT_XY);
//
//        ImageView img1 = new ImageView(this);
//        img1.setImageResource(R.mipmap.homehelp_home);
//        img1.setScaleType(ImageView.ScaleType.FIT_XY);
//
//
//        ImageView img2 = new ImageView(this);
//        img2.setImageResource(R.mipmap.homehelp_home);
//        img2.setScaleType(ImageView.ScaleType.FIT_XY);
//
//        arr.add(img);
//        arr.add(img1);
//        arr.add(img2);
////        vp.setAdapter(new MyVp());
////        vp.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
////            @Override
////            public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
////
////            }
////
////            @Override
////            public void onPageSelected(int position) {
////                pageCurrent = position;
////            }
////
////            @Override
////            public void onPageScrollStateChanged(int state) {
////
////            }
////        });
////        handler.sendEmptyMessageDelayed(LUNBO, 2000);
//    }
    @Override
    protected void onResume() {
        super.onResume();
//        // 缺少权限时, 进入权限配置页面
        boolean boolead = mPermissionsChecker.lacksPermissions(PERMISSIONS);
        if (boolead) {
            startPermissionsActivity();
        }
    }
    private void startPermissionsActivity() {
        PermissionsActivity.startActivityForResult(this, REQUEST_CODE, PERMISSIONS);
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        if (resultCode != RESULT_OK) {
            return;
        }
        // 拒绝时, 关闭页面, 缺少主要权限, 无法运行
        if (requestCode == REQUEST_CODE && resultCode == PermissionsActivity.PERMISSIONS_DENIED) {
            finish();
        }
        switch (requestCode) {
            case SCANNIN_GREQUEST_CODE:
                Bundle bundle = data.getExtras();
                Toast.makeText(NewHomeActivity.this, bundle.getString("result"), Toast.LENGTH_LONG).show();

                break;
        }
    }










    @Override
    public void onClick(View v) {
        if(isNet){
            hint("请链接网络");
            return;
        }
        switch(v.getId()){
            case R.id.home_sear:
                Intent intent = new Intent(NewHomeActivity.this, SearchAty.class);
                intent.putExtra("address",address);
                startActivity(intent);
                break;
            case R.id.home_fix:
                if (mloginsherd.getLoginState() != true) {
                    startActivity(new Intent(NewHomeActivity.this, LoginActivity.class));
                    return;
                } else {
                //保修
                    if (modework==-1){
                        hint("网络无连接请链接后重试");
                        return;}
                startActivity(new Intent(NewHomeActivity.this, MyAddRessRepair.class));}
                break;
        }
    }

    //轮播图的adapter
//    class MyVp extends PagerAdapter {
//
//        @Override
//        public int getCount() {
//            return arr.size();
//        }
//
//        // 来判断显示的是否是同一张图片，这里我们将两个参数相比较返回即可
//        @Override
//        public boolean isViewFromObject(View arg0, Object arg1) {
//            return arg0 == arg1;
//        }
//
//        // PagerAdapter只缓存三张要显示的图片，如果滑动的图片超出了缓存的范围，就会调用这个方法，将图片销毁
//        @Override
//        public void destroyItem(ViewGroup view, int position, Object object) {
//            ((ViewPager) view).removeView((View) arr.get(position));
//        }
//
//        // 当要显示的图片可以进行缓存的时候，会调用这个方法进行显示图片的初始化，我们将要显示的ImageView加入到ViewGroup中，然后作为返回值返回即可
//        @Override
//        public Object instantiateItem(ViewGroup view, int position) {
//            ((ViewPager) view).addView((View) arr.get(position));
//            return arr.get(position);
//        }
//    }
    /**
     * 判断是否右开门key
     */
    String str = "因安卓6版本安全保护，生成快捷开门按钮需要手动设置为允许：" + "\n" + "点击确定-权限-设置单项权限-创建桌面快捷方式，设置为允许即可";
    private static final String PACKAGE_URL_SCHEME = "package:"; // 方案
private void IsKey() {
    if (mloginsherd.getLoginState()!= true) {
        return;
    } else {
        ArrayList<IEGuardKey> opendoorkey = new SaveOpenKeyManage(this).setgainOpenKey();
    if (opendoorkey == null)
        return;
    if (opendoorkey.size() > 0) {
            boolean boo = weather.getBoolean("boo", true);
            if (boo==true) {
                if (Build.VERSION.SDK_INT == 23) {
                    final DoubleButtonDialog dialog = new DoubleButtonDialog(NewHomeActivity.this,str);
                    dialog.setisVisibilitymess();
                    dialog.setTetle_message("设置快捷开门按钮");
                    dialog.getokbtn().setOnClickListener(new View.OnClickListener() {

                        @Override
                        public void onClick(View v) {
                            Intent intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
                            intent.setData(Uri.parse(PACKAGE_URL_SCHEME + getPackageName()));
                            startActivity(intent);
                            editwether.putBoolean("boo", false).commit();
                            dialog.dismiss();
                        }
                    });
                    dialog.getnobtn().setOnClickListener(new View.OnClickListener() {
                        @Override
                        public void onClick(View v) {
                            editwether.putBoolean("boo", false).commit();
                            dialog.dismiss();
                        }
                    });
                } else {
                    createShortCut();
                }
            } else {
                createShortCut();
            }
            boolean IsFitruexu = sharedPreferences.getBoolean("Isbudjexf", true);
            if (IsFitruexu) {
//                startService(floatintetnt = new Intent(NewHomeActivity.this, FloatWindowService.class));
                fb.setVisibility(View.VISIBLE);
            } else {
                return;
            }
            boolean IsFitrueyy = sharedPreferences.getBoolean("Isbudjeyy", true);
            if (IsFitrueyy) {
                startService(intentsensor = new Intent(NewHomeActivity.this, SensorService.class));
            } else {
                return;
            }


        }else{

        fb.setVisibility(View.GONE);
        stopService(new Intent(NewHomeActivity.this, SensorService.class));

    }
}
}
    //检测退出时间
    private long curren = 0;
    @Override
    public void onBackPressed() {

        if ((System.currentTimeMillis() - curren) > 2000) {
            MyToast.show(NewHomeActivity.this, "再按一次退出", 0);
            curren = System.currentTimeMillis();

        } else {
            getSharedPreferences("open_key_judge", Activity.MODE_PRIVATE).edit().clear().commit();
            ExitAppUtlis.getInstance().exit();


        }


    }
//设置天气
    protected void setWeatherDate(String city, String cond, String tmp, String winddir, String windsc, String aqi, String date, String week, String number, String qlty,String temp) {
//            riqis.setText(date);

        home_date.setText(date.substring(date.indexOf("-")+1,date.length()).replace("-","月")+"日");
        home_zouji.setText(week+"  "+cond);
        home_dushu.setText(tmp); //多少度到多少度

        SpannableStringBuilder builder=new SpannableStringBuilder("今日限行 "+number);
        builder.setSpan(new StyleSpan(Typeface.BOLD),0,3, Spannable.SPAN_INCLUSIVE_INCLUSIVE);
        home_xianh.setText(builder );//限行号
//            homeHao.setText(number);
        SpannableStringBuilder builder1=new SpannableStringBuilder("空气质量 "+aqi+" "+qlty);
        builder1.setSpan(new StyleSpan(Typeface.BOLD),0,3, Spannable.SPAN_INCLUSIVE_INCLUSIVE);
        _homekongqi.setText(builder1);
        home_weater_te.setText(temp+"C°");
//            quality.setAir(aqi + "");
        switch (cond) {
            case "晴":
                home_weaterPhone.setImageDrawable(getResources().getDrawable(R.mipmap.dsy_weather_qing));
                break;
            case "多云":
                home_weaterPhone.setImageDrawable(getResources().getDrawable(R.mipmap.dsy_weather_yun));
                break;
            case "晴间多云":
                home_weaterPhone.setImageDrawable(getResources().getDrawable(R.mipmap.dsy_weather_duoyun));
                break;
            case "阴":
                home_weaterPhone.setImageDrawable(getResources().getDrawable(R.mipmap.dsy_weather_yun));
                break;
            case "有风":
                home_weaterPhone.setImageDrawable(getResources().getDrawable(R.mipmap.dsy_weather_feng));
                break;
            case "平静":
                home_weaterPhone.setImageDrawable(getResources().getDrawable(R.mipmap.pingjing));
                break;
            case "微风":
                home_weaterPhone.setImageDrawable(getResources().getDrawable(R.mipmap.dsy_weather_feng));
                break;
            case "和风":
                home_weaterPhone.setImageDrawable(getResources().getDrawable(R.mipmap.dsy_weather_feng));
                break;
            case "清风":
                home_weaterPhone.setImageDrawable(getResources().getDrawable(R.mipmap.dsy_weather_feng));
                break;
            case "强风/劲风":
                home_weaterPhone.setImageDrawable(getResources().getDrawable(R.mipmap.dsy_weather_dafeng));
                break;
            case "疾风":
                home_weaterPhone.setImageDrawable(getResources().getDrawable(R.mipmap.dsy_weather_dafeng));
                break;
            case "大风":
                home_weaterPhone.setImageDrawable(getResources().getDrawable(R.mipmap.dsy_weather_dafeng));
                break;
            case "烈风":
                home_weaterPhone.setImageDrawable(getResources().getDrawable(R.mipmap.dsy_weather_jufeng));
                break;
            case "风暴":
                home_weaterPhone.setImageDrawable(getResources().getDrawable(R.mipmap.dsy_weather_jufeng));
                break;
            case "狂爆风":
                home_weaterPhone.setImageDrawable(getResources().getDrawable(R.mipmap.dsy_weather_jufeng));
                break;

            case "飓风":
                home_weaterPhone.setImageDrawable(getResources().getDrawable(R.mipmap.dsy_weather_longjuanfeng));
                break;
            case "龙卷风":
                home_weaterPhone.setImageDrawable(getResources().getDrawable(R.mipmap.dsy_weather_longjuanfeng));
                break;
            case "热带风暴":
                home_weaterPhone.setImageDrawable(getResources().getDrawable(R.mipmap.dsy_weather_longjuanfeng));
                break;
            case "阵雨":
                home_weaterPhone.setImageDrawable(getResources().getDrawable(R.mipmap.dsy_weather_xiaoyu));
                break;
            case "强阵雨":
                home_weaterPhone.setImageDrawable(getResources().getDrawable(R.mipmap.qiangzhenyu));
                break;
            case "雷阵雨":
                home_weaterPhone.setImageDrawable(getResources().getDrawable(R.mipmap.leizhenyu));
                break;
            case "强雷阵雨":
                home_weaterPhone.setImageDrawable(getResources().getDrawable(R.mipmap.qiangleizhenyu));
                break;
            case "雷阵雨伴有冰雹":
                home_weaterPhone.setImageDrawable(getResources().getDrawable(R.mipmap.lzybansbb));
                break;
            case "小雨":
                home_weaterPhone.setImageDrawable(getResources().getDrawable(R.mipmap.dsy_weather_xiaoyu));
                break;
            case "中雨":
                home_weaterPhone.setImageDrawable(getResources().getDrawable(R.mipmap.zhongyu));
                break;
            case "大雨":
                home_weaterPhone.setImageDrawable(getResources().getDrawable(R.mipmap.dayu));
                break;
            case "极端降雨":
                home_weaterPhone.setImageDrawable(getResources().getDrawable(R.mipmap.jdjiangyu));
                break;
            case "毛毛雨/细雨":
                home_weaterPhone.setImageDrawable(getResources().getDrawable(R.mipmap.maomaoyu));
                break;
            case "暴雨":
                home_weaterPhone.setImageDrawable(getResources().getDrawable(R.mipmap.baoyu));
                break;
            case "大暴雨":
                home_weaterPhone.setImageDrawable(getResources().getDrawable(R.mipmap.dabaoyu));
                break;
            case "特大暴雨":
                home_weaterPhone.setImageDrawable(getResources().getDrawable(R.mipmap.tedabaoyu));
                break;
            case "冻雨":
                home_weaterPhone.setImageDrawable(getResources().getDrawable(R.mipmap.dongyu));
                break;
            case "小雪":
                home_weaterPhone.setImageDrawable(getResources().getDrawable(R.mipmap.xiaoxue));
                break;
            case "中雪":
                home_weaterPhone.setImageDrawable(getResources().getDrawable(R.mipmap.zhogxue));
                break;
            case "大雪":
                home_weaterPhone.setImageDrawable(getResources().getDrawable(R.mipmap.daxue));
                break;
            case "暴雪":
                home_weaterPhone.setImageDrawable(getResources().getDrawable(R.mipmap.baoxue));
                break;
            case "雨夹雪":
                home_weaterPhone.setImageDrawable(getResources().getDrawable(R.mipmap.yujiaxue));
                break;
            case "雨雪天气":
                home_weaterPhone.setImageDrawable(getResources().getDrawable(R.mipmap.yujxtianqi));
                break;
            case "阵雨夹雪":
                home_weaterPhone.setImageDrawable(getResources().getDrawable(R.mipmap.zhenyujx));
                break;
            case "阵雪":
                home_weaterPhone.setImageDrawable(getResources().getDrawable(R.mipmap.zhenxue));
                break;
            case "薄雾":
                home_weaterPhone.setImageDrawable(getResources().getDrawable(R.mipmap.bowu));
                break;

            case "雾":
                home_weaterPhone.setImageDrawable(getResources().getDrawable(R.mipmap.wu));
                break;
            case "霾":
                home_weaterPhone.setImageDrawable(getResources().getDrawable(R.mipmap.mai));
                break;
            case "扬沙":
                home_weaterPhone.setImageDrawable(getResources().getDrawable(R.mipmap.yangsha));
                break;
            case "浮尘":
                home_weaterPhone.setImageDrawable(getResources().getDrawable(R.mipmap.fuchen));
                break;
            case "沙尘暴":
                home_weaterPhone.setImageDrawable(getResources().getDrawable(R.mipmap.shachenbao));
                break;
            case "强沙尘暴":
                home_weaterPhone.setImageDrawable(getResources().getDrawable(R.mipmap.qiangshachenbao));
                break;
            case "热":
                home_weaterPhone.setImageDrawable(getResources().getDrawable(R.mipmap.re));
                break;
            case "冷":
                home_weaterPhone.setImageDrawable(getResources().getDrawable(R.mipmap.leng));
                break;
            case "未知":
                home_weaterPhone.setImageDrawable(getResources().getDrawable(R.mipmap.wz));
                break;
        }
    }



}
